from werkzeug.exceptions import HTTPException

from app.app import create_app
from app.libs.error import APIException
from app.libs.error_code import ServerError

app = create_app()

@app.errorhandler(Exception)
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = e.code
        return APIException(msg, code, error_code)
    else:
        #服务器错误
        # 调试模式
        # log
        if not app.config['DEBUG']:
            msg = str(e)
            code='500'
            error_code='500'
            return APIException(msg, code, error_code)
        else:
            raise e

if __name__=='__main__':

    app.run()